package com.sptpc.springbootmybatis.controller;

import com.sptpc.springbootmybatis.service.CommodityService;
import com.sptpc.springbootmybatis.util.ServerResponse;
import com.sptpc.springbootmybatis.vo.CommodityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/commodity")
public class CommodityController {
    @Autowired
    private CommodityService commodityService;

    //得到commodity的所有信息
    @GetMapping("/")
    @ResponseBody
    public ServerResponse list() {
        return ServerResponse.createBySuccess(commodityService.findAll());
    }

    //更新
    @PostMapping("/update")
    @ResponseBody
    public ServerResponse update(CommodityVo commodityVo) {
        return ServerResponse.createBySuccess(commodityService.update(commodityVo));
    }

}
